package bma.common.langutil.pipeline;

import java.util.LinkedList;
import java.util.List;

/**
 * 通用通道队列构造器（链实现）
 * 
 * @author 关中
 * @since 1.0 (imported from BMA.ESP Project)
 * 
 * @param <TYPE>
 */
public class CommonPipelineBuilderChain<TYPE> implements
		CommonPipelineBuilder<TYPE> {

	protected List<CommonPipelineBuilder<TYPE>> chain = new LinkedList<CommonPipelineBuilder<TYPE>>();

	public List<CommonPipelineBuilder<TYPE>> getChain() {
		return chain;
	}

	public void setChain(List<CommonPipelineBuilder<TYPE>> chain) {
		this.chain = chain;
	}

	public CommonPipelineBuilderChain<TYPE> add(CommonPipelineBuilder<TYPE> b) {
		chain.add(b);
		return this;
	}

	public CommonPipelineBuilderChain<TYPE> addHandler(String name, TYPE item) {
		return add(new CommonPipelineBuilderOne<TYPE>(name, item));
	}

	@Override
	public void buildPipeline(CommonPipeline<TYPE> pipeline) {
		for (CommonPipelineBuilder<TYPE> b : this.chain) {
			b.buildPipeline(pipeline);
		}
	}

}
